<template>
  <page-card title="系统帮助"
             :sub-title="url?'编辑':'新增'"
             :need-back="true">
    <a-form :form="form"
            :label-col="{ span: 6 }"
            :wrapper-col="{ span: 12 }">
      <a-form-item label="ID"
                   v-show="false">
        <a-input v-decorator="['id']" />
      </a-form-item>
      <a-form-item label="页面路径"
                   required>
        <a-input placeholder="请输入" :disabled="url?true:false"
                 oninput="this.value=this.value.replace(/[, ]/g,'')"
                 v-decorator="['url',{rules: [{
                   required: true, message: '请输入页面路径'
                 }]}]" />
      </a-form-item>
      <a-form-item label="标题"
                   required>
        <a-input placeholder="请输入"
                 oninput="this.value=this.value.replace(/[, ]/g,'')"
                 v-decorator="['title',{rules: [{
                   required: true, message: '请输入标题'
                 }]}]" />
      </a-form-item>
      <a-form-item label="内容">
        <a-textarea :maxLength="2000"
                    placeholder="请输入"
                    v-decorator="['content']"
                    style="resize:none; height:85px"></a-textarea>
      </a-form-item>
      <a-form-item label="链接">
        <a-input placeholder="请输入"
                 v-decorator="['link']" />
      </a-form-item>
      <div style="margin-top:20px;text-align:center;">
        <a-space size="small">
          <ZOkButton @click="handleSave">
            <template solt>保存</template>
          </ZOkButton>
        </a-space>
      </div>
    </a-form>
  </page-card>
</template>

<script>
import { saveOrUpdateHelpInfo, getHelpInfoById, deleteHelpInfo } from '../../api/help/index'

export default {
  name: 'HelpEdit',
  extends: null,
  mixins: [],
  components: {},
  props: {},
  data () {
    return {
      form: this.$form.createForm(this),
      id: null,
      url: this.$route.query.url || null// 页面为编辑时的url
    }
  },
  computed: {},
  watch: {},
  created () {
    if (this.url) {
      this.getInfoByID(this.url)
    }
  },
  mounted () { },
  methods: {
    // 保存
    handleSave (e) {
      this.form.validateFields((err, values) => {
        if (err) {
          return
        }
        saveOrUpdateHelpInfo(values).then(res => {
          this.$router.go(-1)
        })
      })
    },

    // 删除、批量删除
    handleDelete () {
      let me = this
      this.confirm({
        title: '提示',
        content: '确定要删除吗？',
        okText: '是',
        cancelText: '否',
        onOk () {
          deleteHelpInfo(me.id).then((res) => {
            me.$router.go(-1)
          })
        },
        onCancel () { }
      })
    },

    // 根据id返回详情
    getInfoByID (url) {
      getHelpInfoById(url).then(res => {
        this.id = res[0].id
        this.form.setFieldsValue(res[0])
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>